package com.tvunetworks.center.user.service.impl;

import com.tvunetworks.center.user.mapper.RoleFeatureMapper;
import com.tvunetworks.center.user.model.RoleFeature;
import com.tvunetworks.center.user.service.RoleFeatureService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Etan Yang
 * @data: 2021/4/7 17:32
 * @program: tvucc-aggregator
 * @description:
 */

@Service
@Slf4j
public class RoleFeatureServiceImpl extends BaseService<RoleFeature> implements RoleFeatureService {
    @Autowired
    private RoleFeatureMapper roleFeatureMapper;


    @Override
    public int batchAddRoleFeature(List<RoleFeature> permissions) {
        if (CollectionUtils.isNotEmpty(permissions)) {
            permissions.forEach(s->{
                super.insert(s);
            });
            return permissions.size();
        }
        return 0;
    }

    @Override
    public void batchDeleteByRoleIdAndFeatureIds(String roleId, List<String> featureIds) {

        if (CollectionUtils.isNotEmpty(featureIds)) {
            roleFeatureMapper.batchDeleteByRoleIdAndFeatureIds(roleId, featureIds);
        }
    }

    @Override
    public List<RoleFeature> getByRoleId(String roleId) {
        return roleFeatureMapper.getByRoleId(roleId);
    }

    @Override
    public int deleteByRoleId(String roleId) {
        return roleFeatureMapper.deleteByRoleId(roleId);
    }

}
